package com.ibm.tivoli.swat.tsam_ec2.tsam;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class XMLParser {
	private static XMLParser singleton = new XMLParser ();
	
	public static XMLParser getInstance () {
		return singleton;
	}
	
	private XMLParser () {
	}
	
	public Document parse (String xml) throws ParserConfigurationException, SAXException, IOException {
		InputStream stream = new ByteArrayInputStream (xml.getBytes());
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance ();
		DocumentBuilder builder = factory.newDocumentBuilder ();
		return builder.parse(stream);
	}
}
